/**
 * @author fenglei.you
 */
Me.TimerDispatcher=function(){
	this.taskMap={};	
}
Me.TimerDispatcher.prototype.regist=function(timerTask){
	var timerId = setInterval(timerTask.run,timerTask.getInterval());
	this.tasksMap[timerId] = timerTask;
	return timerId;
}
Me.TimerDispatcher.prototype.unRegist=function(timerId){
	var timerTask = this.tasksMap[timerId];
	clearInterval(timerId);
	
	this.iteratorCall(timerTask.unRegistListeners);
}
Me.TimerDispatcher.prototype.pause=function(timerId){
	var dest = this.tasksMap[timerId];
	if(dest)dest.pause=true;
	
	this.iteratorCall(dest.pausedListener);
}
Me.TimerDispatcher.prototype.start=function(timerId){
	var dest = this.tasksMap[timerId];
	if(dest)dest.pause=false;
	
	this.iteratorCall(dest.startListener);
}
Me.TimerDispatcher.prototype.iteratorCall=function(listeners){
	if(listeners && listeners.length>0){
		for(var index=0;index<listeners.length;index++){
			if(listeners[index])listeners[index]();			
		}
	}
}

